package com.wu.firstappearingonce;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 字符流中第一个不重复的字符
 *
 * @author lynn
 * @date 2020/8/30 - 20:19
 */
public class Solution {
    //Insert one char from stringstream
    int[] table = new int[256];
    StringBuffer sb = new StringBuffer();


    public void Insert(char ch) {
        sb.append(ch);
        if (table[ch] == 0) {
            table[ch] = 1;
        } else {
            table[ch] += 1;
        }
    }

    //return the first appearence once char in current stringstream
    public char FirstAppearingOnce() {
        char[] str = sb.toString().toCharArray();
        for (char c : str) {
            if (table[c] == 1) {
                return c;
            }
        }
        return '#';
    }
}
